package com.study.springboot.SpringBoot_A.controller;

import com.study.springboot.SpringBoot_A.bean.User;
import com.study.springboot.SpringBoot_A.service.UserService;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author 赵超
 * @Description thymeleaf 模版引擎学习
 * @create 2018-03-23 9:15
 **/
@Controller
public class ThymeleafController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/index")
    public String index(Model model) {
        model.addAttribute("username", "赵超");
//        model.addAttribute("user", new User("赵超", "111111", "18701321850", "bruce", "2018-03-19"));
        model.addAttribute("user", userService.findByUserName("bb"));
        model.addAttribute("count", userService.getCountOfUser());
        model.addAttribute("users", userService.findAll());
        return "index";
    }

    /**
     * 用户查询.
     * @return
     */
    @RequestMapping("/userList")
    public String userInfo(){
        return "userInfo";
    }

    /**
     * 用户添加;
     * @return
     */
    @RequestMapping("/userAdd")
    @RequiresPermissions("userInfo:add")//权限管理;
    public String userInfoAdd(){
        return "userInfoAdd";
    }

    /**
     * 用户删除;
     * @return
     */
    @RequestMapping("/userDel")
    @RequiresPermissions("userInfo:del")//权限管理;
    public String userDel(){
        return "userInfoDel";
    }
}
